package com.example.book.model;

import com.example.book.enums.ResultStatus;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/7/28
 * Time: 21:13
 */
@Data
public class Result<T> {
    private ResultStatus code;
    private String errorMessage;
    private T data;

    public static <T> Result success(T data){
        Result<Object> result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result noLogin(){
        Result<Object> result = new Result<>();
        result.setCode(ResultStatus.NOLOGIN);
        result.setErrorMessage("用户未登录");
        return result;
    }

    public static Result fail(String errorMessage){
        Result<Object> result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrorMessage(errorMessage);
        return result;
    }
}
